package com.akk.utils.exception;

import com.akk.utils.RestResponse;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionControllerAdvice {

    @ExceptionHandler(value = UnauthorizedException.class)
    @ResponseBody
    public RestResponse unauthorized(UnauthorizedException e){
        return RestResponse.build("1001","权限不足");
    }

    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public Map exception(BusinessException exception){
        Map<String,Object> result = new HashMap<>();
        result.put("code",exception.getCode());
        result.put("message",exception.getMessage());
        return result;
    }

}
